function getRenderHtml(attr,data){
	var dataType = attr.dataType || "string";
	var dict = attr.dict;

	var value = data[attr.field];
	if(value == null){
		value = "";
	}

	if(dataType == 'mulDict'){
		dataType = "mulDict";
	}else{
		if(dict){
			dataType = "dict";
		}
	}


	if(dataType == "img"){
		dataType = "file";
	}
	return htmlRender[dataType](attr,value,dict);
}

var  valueValidate = {

}

var imgLocation = "";
var htmlRender = {
		string : function(data,value){
			return '<div class="form-group"><label class="col-sm-4 control-label">'+data.title+'：</label><div class="col-sm-5"><input value="'+value+'" class="form-control" type="text"  name="'+data.field+'"></input></div></div>';
		},
		bigstring:function(data,value){
			return '<div class="form-group"><label class="col-sm-4 control-label">'+data.title+'：</label><div class="col-sm-5"><textarea style="resize:none;width:100%;height:100px;"  value="'+value+'" class="form-control" type="text"  name="'+data.field+'">'+value+'</textarea></div></div>';
		},
		hidden:function(data,value)	{
			return '<div class="form-group"><div class="col-sm-5"><input value="'+value+'" class="form-control" type="hidden"  name="'+data.field+'"></input></div></div>';
		},
		int:function(data,value){
			return '<div class="form-group"><label class="col-sm-4 control-label">'+data.title+'：</label><div class="col-sm-5"><input value="'+value+'" class="form-control" type="number"  name="'+data.field+'"></input></div></div>';
		},
		img:function(data,value){
			var imgStr ='<div><button onclick="return chooseFile(this)" >上传</button></div>';
			if(value){
				var imgDom = "<div class='imgContainer'>";
				var imgs = value.split(",");
				for(var i = 0;i<imgs.length;i++){
					var img = imgs[i];
					var path = imgLocation+img;
					imgDom+='<div onclick="removeImg(this)" style="display:inline-block;margin:10px"><img style="width:50px;height:50px" name="'+img+'" src="'+path+'"/></div>'
				}

				imgDom+="</div>";
			}


			return '<div class="form-group"><label class="col-sm-4 control-label">'+data.title+'：</label><div class="col-sm-5"><input style="border:none" type="hidden" value="'+value+'" class="form-control" name="'+data.field+'" ></input>\
			'+imgStr+imgDom+'\
			</div></div>';
		},
		dict:function(data,value,dict){
//			<input value="'+value+'" ></input>
			var str = "";
			for(var key in dict){
				if(value == key){
					str+='<option  selected="selected" value="'+key+'">'+dict[key]+'</option>';
				}else{
					str+='<option value="'+key+'">'+dict[key]+'</option>';
				}
			}
			return '<div class="form-group"><label class="col-sm-4 control-label">'+data.title+'：</label><div class="col-sm-5"><select onchange="changeEvent(\''+data.field+'\')" class="form-control" id="'+data.field+'" type="text"  name="'+data.field+'">'+str+'</select></div></div>';
		},

		mulDict:function(data,value,dict){
//			<input value="'+value+'" ></input>
			var str = "";
			for(var key in dict){
				if(value == key){
					str+='<option  selected="selected" value="'+key+'">'+dict[key]+'</option>';
				}else{
					str+='<option value="'+key+'">'+dict[key]+'</option>';
				}
			}
			return '<div class="form-group"><label class="col-sm-4 control-label">'+data.title+'：</label><div class="col-sm-5"><select multiple class="form-control multiplepicker" type="text"  name="'+data.field+'">'+str+'</select></div></div>';
		},
		file:function(data,value){
			var imgStr ='<div><button onclick="return chooseFile(this)" >上传</button></div>';
			var imgDom = "<div class='imgContainer'>";
			if(value){
				var imgs = value.split(",");
				for(var i = 0;i<imgs.length;i++){
					var img = imgs[i];
					var path = imgLocation+img;
					var index= img.lastIndexOf(".");
					var ext = img.substr(index+1);
					if(isAssetTypeAnImage(ext)){
						imgDom+='<div class="child_item" style="display:inline-block;margin:10px"><div style="display:inline-block"><img class="element" style="width:50px;height:50px"  onclick="showImg(this)" name="'+img+'" src="'+path+'"/></div><div onclick="removeImg(this)" style="cursor:pointer;display:inline-block;margin: 0 3px;font-size: 10px;">移除</div></div>';
					}else{
						imgDom+='<div class="child_item"  style="display:inline-block;margin:10px"><div style="display:inline-block"><a class="element" target="_blank"  name="'+img+'" href="'+path+'">'+img+'</a></div><div onclick="removeImg(this)" style="cursor:pointer;display:inline-block;margin: 0 3px;font-size: 10px;">移除</div></div>';

					}
				}
			}
			imgDom+="</div>";

			return '<div class="form-group"><label class="col-sm-4 control-label">'+data.title+'：</label><div class="col-sm-8"><input style="border:none" type="hidden" value="'+value+'" class="form-control" name="'+data.field+'" ></input>\
			'+imgStr+imgDom+'\
			</div></div>';
		},
		datetime:function(data,value){
			let randon = Math.random();
			let timeid ="timer_"+randon;
			return '<div class="form-group"><label class="col-sm-4 control-label">'+data.title+'：</label><div class="col-sm-5"><input value="'+value+'" class="form-control datepicker" type="date" id="'+timeid+'"   name="'+data.field+'"></input></div></div>';
		}

}
var trigerObj = null;
function removeImg(obj){
	var parent = $(obj).parents(".child_item").parent()
	$(obj).parents(".child_item").remove();
	handerImgValue(parent);
}

function handelerResult(res){
	var parn = $(trigerObj).parent().parent();
	var img = res.path;
	var index= img.lastIndexOf(".");
	var ext = img.substr(index+1);
	var path = imgLocation+img;
	if(isAssetTypeAnImage(ext)){
		$(".imgContainer",parn).append('<div class="child_item" style="display:inline-block;margin:10px"><div style="display:inline-block"><img class="element" style="width:50px;height:50px" onclick="showImg(this)" name="'+img+'" src="'+path+'"/></div><div onclick="removeImg(this)" style="cursor:pointer;display:inline-block;margin: 0 3px;font-size: 10px;">移除</div></div>');
	}else{
		$(".imgContainer",parn).append('<div class="child_item"  style="display:inline-block;margin:10px"><div style="display:inline-block"><a class="element" target="_blank"  name="'+img+'"  href="'+path+'">'+img+'</a></div><div onclick="removeImg(this)" style="cursor:pointer;display:inline-block;margin: 0 3px;font-size: 10px;">移除</div></div>');

	}
	handerImgValue(trigerObj);
}

function isAssetTypeAnImage(ext) {
	 return [
	 'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'].
	 indexOf(ext.toLowerCase()) !== -1;
	}

function handerImgValue(obj){
	var parent = $(obj).parents(".form-group");
	var imgs = $(".imgContainer .element",parent)
	var values = "";
	for(var i=0;i<imgs.length;i++){
		var img = imgs[i];
		var name = $(img).attr("name");
		if(values.length>0){
			values+=",";
		}
		values+=name;
	}
	$("input",parent).val(values);
}

function chooseFile(obj){
	trigerObj = obj;
	$("#uploadFile").click();
	return false;
}
function changeEvent(id){
	if(id == 'productId'){
		productChange()
	}
}
function sendData(url,data,callback){
	let index = layer.load();
	$.ajax({
		url:"http://127.0.0.1:8090/"+url,
		type: 'POST', // 请求类型
		contentType: 'application/json', // 设置内容类型为JSON
		data: JSON.stringify(data), // 发送JSON字符串
		success:function(res){
			layer.close(index);
			if(res.code == 200){
				if(callback){
					callback(res);
				}
			}
		}
	})
}
